package com.bwie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bwie.utils.R;
import com.bwie.vo.PageInfoVo;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.mapper.ContractMapper;
import com.bwie.pojo.Contract;
import com.bwie.service.ContractService;
@Service
public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> implements ContractService{

    @Autowired
    private ContractMapper contractMapper;
    @Autowired
    StringRedisTemplate redisTemplate;
    @Override
    public R getContractList(PageInfoVo pageInfoVo) {
        Page<Contract> page = new Page<>(pageInfoVo.getPageNum(), pageInfoVo.getPageSize());
        Page<Contract> contractPage = contractMapper.getContractList(page, pageInfoVo);
        return R.OK(contractPage);
    }

    @Override
    public R addContract(Contract contract) {
        LambdaQueryWrapper<Contract> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Contract::getName,contract.getName());
        Contract contract1 = contractMapper.selectOne(wrapper);
        if(contract1!=null){
            return R.ERROR(500,"合同已存在");
        }
        contract.setCreateTime(new Date());
        contract.setStopTime(new Date());
        contract.setContractStatus(0);
        contractMapper.insert(contract);
        return R.OK();
    }
}
